{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 64,
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd\n",
    "import requests\n",
    "key_lin =\"131427e6733a34a09c06e84d7905b23d\""
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 获取地理/逆地理编码"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 65,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'status': '1', 'info': 'OK', 'infocode': '10000', 'count': '1', 'geocodes': [{'formatted_address': '广东省广州市从化区中山大学南方学院', 'country': '中国', 'province': '广东省', 'citycode': '020', 'city': '广州市', 'district': '从化区', 'township': [], 'neighborhood': {'name': [], 'type': []}, 'building': {'name': [], 'type': []}, 'adcode': '440117', 'street': [], 'number': [], 'location': '113.679287,23.632575', 'level': '兴趣点'}]}\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>formatted_address</th>\n",
       "      <th>country</th>\n",
       "      <th>province</th>\n",
       "      <th>citycode</th>\n",
       "      <th>city</th>\n",
       "      <th>district</th>\n",
       "      <th>township</th>\n",
       "      <th>adcode</th>\n",
       "      <th>street</th>\n",
       "      <th>number</th>\n",
       "      <th>location</th>\n",
       "      <th>level</th>\n",
       "      <th>neighborhood.name</th>\n",
       "      <th>neighborhood.type</th>\n",
       "      <th>building.name</th>\n",
       "      <th>building.type</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>广东省广州市从化区中山大学南方学院</td>\n",
       "      <td>中国</td>\n",
       "      <td>广东省</td>\n",
       "      <td>020</td>\n",
       "      <td>广州市</td>\n",
       "      <td>从化区</td>\n",
       "      <td>[]</td>\n",
       "      <td>440117</td>\n",
       "      <td>[]</td>\n",
       "      <td>[]</td>\n",
       "      <td>113.679287,23.632575</td>\n",
       "      <td>兴趣点</td>\n",
       "      <td>[]</td>\n",
       "      <td>[]</td>\n",
       "      <td>[]</td>\n",
       "      <td>[]</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   formatted_address country province citycode city district township  adcode  \\\n",
       "0  广东省广州市从化区中山大学南方学院      中国      广东省      020  广州市      从化区       []  440117   \n",
       "\n",
       "  street number              location level neighborhood.name  \\\n",
       "0     []     []  113.679287,23.632575   兴趣点                []   \n",
       "\n",
       "  neighborhood.type building.name building.type  \n",
       "0                []            []            []  "
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "中大南方地理编码: 113.679287,23.632575\n"
     ]
    }
   ],
   "source": [
    "def geocode(address,city=None,batch=None,sig=None)->dict:\n",
    "    \"\"\"获取地理编码\"\"\"\n",
    "    url = 'https://restapi.amap.com/v3/geocode/geo?parameters'\n",
    "    params={\n",
    "        'key': key_lin,\n",
    "        'address':address,\n",
    "        'city':city,\n",
    "        'batch':batch,\n",
    "        'sig':sig,\n",
    "        'output':'json'\n",
    "    }\n",
    "    response = requests.get(url,params=params)\n",
    "    data = response.json()\n",
    "    return data\n",
    "中大南方 = geocode(address='广东省广州市从化区中山大学南方学院')\n",
    "print(中大南方)\n",
    "df_中大南方地理编码 = pd.json_normalize(中大南方['geocodes'])\n",
    "display(df_中大南方地理编码)\n",
    "中大南方地理编码 = 中大南方['geocodes'][0]['location']\n",
    "print(\"中大南方地理编码:\",中大南方地理编码)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 66,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'status': '1', 'regeocode': {'addressComponent': {'city': '广州市', 'province': '广东省', 'adcode': '440117', 'district': '从化区', 'towncode': '440117103000', 'streetNumber': {'number': '7号', 'location': '113.6786,23.6333289', 'direction': '西北', 'distance': '109.203', 'street': '博学路'}, 'country': '中国', 'township': '温泉镇', 'businessAreas': [[]], 'building': {'name': [], 'type': []}, 'neighborhood': {'name': [], 'type': []}, 'citycode': '020'}, 'formatted_address': '广东省广州市从化区温泉镇中山大学南方学院'}, 'info': 'OK', 'infocode': '10000'}\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>0</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>status</th>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>info</th>\n",
       "      <td>OK</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>infocode</th>\n",
       "      <td>10000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>regeocode.addressComponent.city</th>\n",
       "      <td>广州市</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>regeocode.addressComponent.province</th>\n",
       "      <td>广东省</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>regeocode.addressComponent.adcode</th>\n",
       "      <td>440117</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>regeocode.addressComponent.district</th>\n",
       "      <td>从化区</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>regeocode.addressComponent.towncode</th>\n",
       "      <td>440117103000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>regeocode.addressComponent.streetNumber.number</th>\n",
       "      <td>7号</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>regeocode.addressComponent.streetNumber.location</th>\n",
       "      <td>113.6786,23.6333289</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>regeocode.addressComponent.streetNumber.direction</th>\n",
       "      <td>西北</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>regeocode.addressComponent.streetNumber.distance</th>\n",
       "      <td>109.203</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>regeocode.addressComponent.streetNumber.street</th>\n",
       "      <td>博学路</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>regeocode.addressComponent.country</th>\n",
       "      <td>中国</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>regeocode.addressComponent.township</th>\n",
       "      <td>温泉镇</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>regeocode.addressComponent.businessAreas</th>\n",
       "      <td>[[]]</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>regeocode.addressComponent.building.name</th>\n",
       "      <td>[]</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>regeocode.addressComponent.building.type</th>\n",
       "      <td>[]</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>regeocode.addressComponent.neighborhood.name</th>\n",
       "      <td>[]</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>regeocode.addressComponent.neighborhood.type</th>\n",
       "      <td>[]</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>regeocode.addressComponent.citycode</th>\n",
       "      <td>020</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>regeocode.formatted_address</th>\n",
       "      <td>广东省广州市从化区温泉镇中山大学南方学院</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                                                                      0\n",
       "status                                                                1\n",
       "info                                                                 OK\n",
       "infocode                                                          10000\n",
       "regeocode.addressComponent.city                                     广州市\n",
       "regeocode.addressComponent.province                                 广东省\n",
       "regeocode.addressComponent.adcode                                440117\n",
       "regeocode.addressComponent.district                                 从化区\n",
       "regeocode.addressComponent.towncode                        440117103000\n",
       "regeocode.addressComponent.streetNumber.number                       7号\n",
       "regeocode.addressComponent.streetNumber.location    113.6786,23.6333289\n",
       "regeocode.addressComponent.streetNumber.direction                    西北\n",
       "regeocode.addressComponent.streetNumber.distance                109.203\n",
       "regeocode.addressComponent.streetNumber.street                      博学路\n",
       "regeocode.addressComponent.country                                   中国\n",
       "regeocode.addressComponent.township                                 温泉镇\n",
       "regeocode.addressComponent.businessAreas                           [[]]\n",
       "regeocode.addressComponent.building.name                             []\n",
       "regeocode.addressComponent.building.type                             []\n",
       "regeocode.addressComponent.neighborhood.name                         []\n",
       "regeocode.addressComponent.neighborhood.type                         []\n",
       "regeocode.addressComponent.citycode                                 020\n",
       "regeocode.formatted_address                        广东省广州市从化区温泉镇中山大学南方学院"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "def regeocode(location,poitype=None,radius=None,extensions=\"base\",batch=False,roadlevel=None,sig=None,homeorcorp=None)->dict:\n",
    "    \"\"\"获取逆地理编码\"\"\"\n",
    "    url = 'https://restapi.amap.com/v3/geocode/regeo?parameters'\n",
    "    params={\n",
    "        'key': key_lin,\n",
    "        'location':location,\n",
    "        'poitype':poitype,\n",
    "        'radius':radius,\n",
    "        'extensions':extensions,\n",
    "        'batch':batch,\n",
    "        'roadlevel':roadlevel,\n",
    "        'homeorcorp':homeorcorp,\n",
    "        'sig':sig,\n",
    "        'output':'json'\n",
    "    }\n",
    "    response = requests.get(url,params=params)\n",
    "    data = response.json()\n",
    "    return data\n",
    "\n",
    "中大南方逆地理编码_base = regeocode(中大南方地理编码)\n",
    "print(中大南方逆地理编码_base)\n",
    "df_中大南方逆地理编码 = pd.json_normalize(中大南方逆地理编码_base).T\n",
    "display(df_中大南方逆地理编码)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "* 背后的功能：信息检索"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 路径规划"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 67,
   "metadata": {},
   "outputs": [],
   "source": [
    "def walking(origin,destination,sig=None)->dict:\n",
    "    url = 'https://restapi.amap.com/v3/direction/walking?parameters'\n",
    "    params={\n",
    "        'key':key_lin,\n",
    "        'origin':origin,\n",
    "        'destination':destination,\n",
    "        'output':'json'\n",
    "    }\n",
    "    response = requests.get(url,params=params)\n",
    "    data = response.json()\n",
    "    return data"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 68,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "(起点)中大南方_location: 113.679287,23.632575 (终点)龙岗社区居委会_location: 113.669129,23.600956\n"
     ]
    }
   ],
   "source": [
    "龙岗社区居委会 = geocode('广东省广州市从化区龙岗社区居委会')  # 获取地理编码\n",
    "龙岗社区居委会_location = 龙岗社区居委会['geocodes'][0]['location'] #获取geocodes中的location坐标点——经纬度\n",
    "中大南方_location = 中大南方['geocodes'][0]['location']\n",
    "print(\"(起点)中大南方_location:\",中大南方_location,\"(终点)龙岗社区居委会_location:\",龙岗社区居委会_location)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 69,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>instruction</th>\n",
       "      <th>orientation</th>\n",
       "      <th>road</th>\n",
       "      <th>distance</th>\n",
       "      <th>duration</th>\n",
       "      <th>polyline</th>\n",
       "      <th>action</th>\n",
       "      <th>assistant_action</th>\n",
       "      <th>walk_type</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>向南步行161米右转</td>\n",
       "      <td>南</td>\n",
       "      <td>[]</td>\n",
       "      <td>161</td>\n",
       "      <td>129</td>\n",
       "      <td>113.679592,23.632088;113.679609,23.631003;113....</td>\n",
       "      <td>右转</td>\n",
       "      <td>[]</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>向西步行99米左转</td>\n",
       "      <td>西</td>\n",
       "      <td>[]</td>\n",
       "      <td>99</td>\n",
       "      <td>79</td>\n",
       "      <td>113.67964,23.630634;113.679362,23.630521;113.6...</td>\n",
       "      <td>左转</td>\n",
       "      <td>[]</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>向南步行237米左转</td>\n",
       "      <td>南</td>\n",
       "      <td>[]</td>\n",
       "      <td>237</td>\n",
       "      <td>190</td>\n",
       "      <td>113.678711,23.63036;113.678711,23.62934;113.67...</td>\n",
       "      <td>左转</td>\n",
       "      <td>[]</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>向南步行498米向右前方行走</td>\n",
       "      <td>南</td>\n",
       "      <td>[]</td>\n",
       "      <td>498</td>\n",
       "      <td>398</td>\n",
       "      <td>113.678273,23.628368;113.678572,23.628338;113....</td>\n",
       "      <td>向右前方行走</td>\n",
       "      <td>[]</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>向西南步行715米左转</td>\n",
       "      <td>西南</td>\n",
       "      <td>[]</td>\n",
       "      <td>715</td>\n",
       "      <td>572</td>\n",
       "      <td>113.678572,23.624653;113.678559,23.62451;113.6...</td>\n",
       "      <td>左转</td>\n",
       "      <td>[]</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>向东南步行406米向右前方行走</td>\n",
       "      <td>东南</td>\n",
       "      <td>[]</td>\n",
       "      <td>406</td>\n",
       "      <td>325</td>\n",
       "      <td>113.675299,23.620048;113.675642,23.619991;113....</td>\n",
       "      <td>向右前方行走</td>\n",
       "      <td>[]</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>沿乌土街向南步行1380米右转</td>\n",
       "      <td>南</td>\n",
       "      <td>乌土街</td>\n",
       "      <td>1380</td>\n",
       "      <td>1104</td>\n",
       "      <td>113.678181,23.617652;113.678095,23.617205;113....</td>\n",
       "      <td>右转</td>\n",
       "      <td>[]</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>沿乌土街向西南步行165米直行</td>\n",
       "      <td>西南</td>\n",
       "      <td>乌土街</td>\n",
       "      <td>165</td>\n",
       "      <td>132</td>\n",
       "      <td>113.677535,23.605668;113.676988,23.605373;113....</td>\n",
       "      <td>直行</td>\n",
       "      <td>[]</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>沿934县道向西步行118米直行</td>\n",
       "      <td>西</td>\n",
       "      <td>934县道</td>\n",
       "      <td>118</td>\n",
       "      <td>94</td>\n",
       "      <td>113.676159,23.604883;113.675929,23.604831;113....</td>\n",
       "      <td>直行</td>\n",
       "      <td>[]</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>沿桃园东路向西南步行673米向右前方行走</td>\n",
       "      <td>西南</td>\n",
       "      <td>桃园东路</td>\n",
       "      <td>673</td>\n",
       "      <td>538</td>\n",
       "      <td>113.675009,23.604735;113.674236,23.604683;113....</td>\n",
       "      <td>向右前方行走</td>\n",
       "      <td>[]</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>沿桃园东路向西南步行117米到达目的地</td>\n",
       "      <td>西南</td>\n",
       "      <td>桃园东路</td>\n",
       "      <td>117</td>\n",
       "      <td>94</td>\n",
       "      <td>113.669714,23.601897;113.66964,23.601771;113.6...</td>\n",
       "      <td>[]</td>\n",
       "      <td>到达目的地</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "             instruction orientation   road distance duration  \\\n",
       "0             向南步行161米右转           南     []      161      129   \n",
       "1              向西步行99米左转           西     []       99       79   \n",
       "2             向南步行237米左转           南     []      237      190   \n",
       "3         向南步行498米向右前方行走           南     []      498      398   \n",
       "4            向西南步行715米左转          西南     []      715      572   \n",
       "5        向东南步行406米向右前方行走          东南     []      406      325   \n",
       "6        沿乌土街向南步行1380米右转           南    乌土街     1380     1104   \n",
       "7        沿乌土街向西南步行165米直行          西南    乌土街      165      132   \n",
       "8       沿934县道向西步行118米直行           西  934县道      118       94   \n",
       "9   沿桃园东路向西南步行673米向右前方行走          西南   桃园东路      673      538   \n",
       "10   沿桃园东路向西南步行117米到达目的地          西南   桃园东路      117       94   \n",
       "\n",
       "                                             polyline  action  \\\n",
       "0   113.679592,23.632088;113.679609,23.631003;113....      右转   \n",
       "1   113.67964,23.630634;113.679362,23.630521;113.6...      左转   \n",
       "2   113.678711,23.63036;113.678711,23.62934;113.67...      左转   \n",
       "3   113.678273,23.628368;113.678572,23.628338;113....  向右前方行走   \n",
       "4   113.678572,23.624653;113.678559,23.62451;113.6...      左转   \n",
       "5   113.675299,23.620048;113.675642,23.619991;113....  向右前方行走   \n",
       "6   113.678181,23.617652;113.678095,23.617205;113....      右转   \n",
       "7   113.677535,23.605668;113.676988,23.605373;113....      直行   \n",
       "8   113.676159,23.604883;113.675929,23.604831;113....      直行   \n",
       "9   113.675009,23.604735;113.674236,23.604683;113....  向右前方行走   \n",
       "10  113.669714,23.601897;113.66964,23.601771;113.6...      []   \n",
       "\n",
       "   assistant_action walk_type  \n",
       "0                []         0  \n",
       "1                []         0  \n",
       "2                []         0  \n",
       "3                []         0  \n",
       "4                []         0  \n",
       "5                []         0  \n",
       "6                []         0  \n",
       "7                []         0  \n",
       "8                []         0  \n",
       "9                []         0  \n",
       "10            到达目的地         0  "
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/plain": [
       "0               向南步行161米右转\n",
       "1                向西步行99米左转\n",
       "2               向南步行237米左转\n",
       "3           向南步行498米向右前方行走\n",
       "4              向西南步行715米左转\n",
       "5          向东南步行406米向右前方行走\n",
       "6          沿乌土街向南步行1380米右转\n",
       "7          沿乌土街向西南步行165米直行\n",
       "8         沿934县道向西步行118米直行\n",
       "9     沿桃园东路向西南步行673米向右前方行走\n",
       "10     沿桃园东路向西南步行117米到达目的地\n",
       "Name: instruction, dtype: object"
      ]
     },
     "execution_count": 69,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "中大南方_龙岗社区居委会 = walking(中大南方_location,龙岗社区居委会_location)\n",
    "df_步行路径规划 = pd.json_normalize(中大南方_龙岗社区居委会[\"route\"][\"paths\"][0]['steps'])\n",
    "display(df_步行路径规划)\n",
    "df_步行路径规划[\"instruction\"]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "* 背后的功能：推荐算法、信息检索、人机交互。"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 行政区域查询"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 70,
   "metadata": {},
   "outputs": [],
   "source": [
    "def checking(keywords,subdistrict=None,extensions='base')->dict:\n",
    "    url = 'https://restapi.amap.com/v3/config/district?parameters'\n",
    "    params={\n",
    "        'key':key_lin,\n",
    "        'keywords':keywords,\n",
    "        'subdistrict':subdistrict,\n",
    "        'output':'json',\n",
    "    }\n",
    "    response = requests.get(url,params=params)\n",
    "    data = response.json()\n",
    "    return data"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 71,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'status': '1', 'info': 'OK', 'infocode': '10000', 'count': '1', 'suggestion': {'keywords': [], 'cities': []}, 'districts': [{'citycode': [], 'adcode': '440000', 'name': '广东省', 'center': '113.280637,23.125178', 'level': 'province', 'districts': [{'citycode': '0758', 'adcode': '441200', 'name': '肇庆市', 'center': '112.472529,23.051546', 'level': 'city', 'districts': []}, {'citycode': '0757', 'adcode': '440600', 'name': '佛山市', 'center': '113.122717,23.028762', 'level': 'city', 'districts': []}, {'citycode': '0754', 'adcode': '440500', 'name': '汕头市', 'center': '116.708463,23.37102', 'level': 'city', 'districts': []}, {'citycode': '0752', 'adcode': '441300', 'name': '惠州市', 'center': '114.412599,23.079404', 'level': 'city', 'districts': []}, {'citycode': '0755', 'adcode': '440300', 'name': '深圳市', 'center': '114.085947,22.547', 'level': 'city', 'districts': []}, {'citycode': '0756', 'adcode': '440400', 'name': '珠海市', 'center': '113.553986,22.224979', 'level': 'city', 'districts': []}, {'citycode': '0759', 'adcode': '440800', 'name': '湛江市', 'center': '110.364977,21.274898', 'level': 'city', 'districts': []}, {'citycode': '0662', 'adcode': '441700', 'name': '阳江市', 'center': '111.975107,21.859222', 'level': 'city', 'districts': []}, {'citycode': '0660', 'adcode': '441500', 'name': '汕尾市', 'center': '115.364238,22.774485', 'level': 'city', 'districts': []}, {'citycode': '0768', 'adcode': '445100', 'name': '潮州市', 'center': '116.632301,23.661701', 'level': 'city', 'districts': []}, {'citycode': '0750', 'adcode': '440700', 'name': '江门市', 'center': '113.094942,22.590431', 'level': 'city', 'districts': []}, {'citycode': '0766', 'adcode': '445300', 'name': '云浮市', 'center': '112.044439,22.929801', 'level': 'city', 'districts': []}, {'citycode': '0767', 'adcode': '442100', 'name': '东沙群岛', 'center': '116.887312,20.617512', 'level': 'city', 'districts': []}, {'citycode': '0668', 'adcode': '440900', 'name': '茂名市', 'center': '110.919229,21.659751', 'level': 'city', 'districts': []}, {'citycode': '0762', 'adcode': '441600', 'name': '河源市', 'center': '114.697802,23.746266', 'level': 'city', 'districts': []}, {'citycode': '0753', 'adcode': '441400', 'name': '梅州市', 'center': '116.117582,24.299112', 'level': 'city', 'districts': []}, {'citycode': '0769', 'adcode': '441900', 'name': '东莞市', 'center': '113.746262,23.046237', 'level': 'city', 'districts': []}, {'citycode': '0663', 'adcode': '445200', 'name': '揭阳市', 'center': '116.355733,23.543778', 'level': 'city', 'districts': []}, {'citycode': '0763', 'adcode': '441800', 'name': '清远市', 'center': '113.051227,23.685022', 'level': 'city', 'districts': []}, {'citycode': '0751', 'adcode': '440200', 'name': '韶关市', 'center': '113.591544,24.801322', 'level': 'city', 'districts': []}, {'citycode': '020', 'adcode': '440100', 'name': '广州市', 'center': '113.280637,23.125178', 'level': 'city', 'districts': []}, {'citycode': '0760', 'adcode': '442000', 'name': '中山市', 'center': '113.382391,22.521113', 'level': 'city', 'districts': []}]}]}\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>citycode</th>\n",
       "      <th>adcode</th>\n",
       "      <th>name</th>\n",
       "      <th>center</th>\n",
       "      <th>level</th>\n",
       "      <th>districts</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>[]</td>\n",
       "      <td>440000</td>\n",
       "      <td>广东省</td>\n",
       "      <td>113.280637,23.125178</td>\n",
       "      <td>province</td>\n",
       "      <td>[{'citycode': '0758', 'adcode': '441200', 'nam...</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "  citycode  adcode name                center     level  \\\n",
       "0       []  440000  广东省  113.280637,23.125178  province   \n",
       "\n",
       "                                           districts  \n",
       "0  [{'citycode': '0758', 'adcode': '441200', 'nam...  "
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "示例_a = checking(keywords='广东省',subdistrict=1)  #subdisrtict {0，1，2，3}\n",
    "print(示例_a)\n",
    "df_广东省 = pd.json_normalize(示例_a['districts'])\n",
    "display(df_广东省)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "* 背后功能：信息检索"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 搜索poi"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "* 关键字搜索：通过用POI的关键字进行条件搜索，例如：肯德基、朝阳公园等；同时支持设置POI类型搜索，例如：银行\n",
    "* 周边搜索：在用户传入经纬度坐标点附近，在设定的范围内，按照关键字或POI类型搜索；\n",
    "* 多边形搜索：在多边形区域内进行搜索\n",
    "* ID查询：通过POI ID，查询某个POI详情，建议可同输入提示API配合使用"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 72,
   "metadata": {},
   "outputs": [],
   "source": [
    "def search_poi(keywords,city,citylimit=None,sig=None)->dict:\n",
    "    url = 'https://restapi.amap.com/v3/place/text?parameters'\n",
    "    params = {\n",
    "        'key': key_lin,\n",
    "        'keywords': keywords,\n",
    "        'city': city,\n",
    "        'citylimit':citylimit,\n",
    "        'sig': sig,\n",
    "        'output': 'json'\n",
    "    }\n",
    "    response = requests.get(url,params=params)\n",
    "    data = response.json()\n",
    "    return data"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 73,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'status': '1', 'count': '899', 'info': 'OK', 'infocode': '10000', 'suggestion': {'keywords': [], 'cities': []}, 'pois': [{'id': 'B00141K2HX', 'parent': [], 'childtype': [], 'name': '卡朋西餐馆', 'type': '餐饮服务;外国餐厅;西餐厅(综合风味)', 'typecode': '050201', 'biz_type': 'diner', 'address': '较场西路16号之二原综合楼西南角2层,3层(麦当劳南侧)', 'location': '113.283377,23.123732', 'tel': '020-83813235', 'distance': [], 'biz_ext': {'rating': '4.0', 'cost': '60.00', 'meal_ordering': '0'}, 'pname': '广东省', 'cityname': '广州市', 'adname': '越秀区', 'importance': [], 'shopid': [], 'shopinfo': '0', 'poiweight': [], 'photos': [{'url': 'http://store.is.autonavi.com/showpic/0ddff8783a0dca72ce95aa619b5be796', 'provider': [], 'title': []}, {'url': 'http://store.is.autonavi.com/showpic/7a6ce2df4c3ead21453ad8508baeb510', 'provider': [], 'title': []}, {'url': 'http://store.is.autonavi.com/showpic/03e7925376034efc9d041bbddac843de', 'provider': [], 'title': []}]}, {'id': 'B00140B248', 'parent': 'B00140U0SG', 'childtype': '201', 'name': '笑味轩(中华广场)', 'type': '餐饮服务;外国餐厅;韩国料理', 'typecode': '050203', 'biz_type': 'diner', 'address': '中山三路33号中华广场7F层748', 'location': '113.282144,23.125857', 'tel': '020-83739000', 'distance': [], 'biz_ext': {'rating': '4.0', 'cost': '70.00', 'meal_ordering': '0'}, 'pname': '广东省', 'cityname': '广州市', 'adname': '越秀区', 'importance': [], 'shopid': [], 'shopinfo': '0', 'poiweight': [], 'photos': [{'url': 'http://store.is.autonavi.com/showpic/3ef2cafa5cce88dc78768a454c9d9d4f', 'provider': [], 'title': []}, {'url': 'http://store.is.autonavi.com/showpic/f677e531ae85515f1d2a10f661a49895', 'provider': [], 'title': '菜品'}, {'url': 'http://store.is.autonavi.com/showpic/ca3eda6a25bcdc7ec88b649442853b42', 'provider': [], 'title': '菜品'}]}, {'id': 'B00140T61P', 'parent': [], 'childtype': [], 'name': '稻香海鲜点心酒家(万斯店)', 'type': '餐饮服务;中餐厅;火锅店', 'typecode': '050117', 'biz_type': 'diner', 'address': '白云路22号8号公馆2层(近嘉星广场)', 'location': '113.282542,23.117798', 'tel': '020-83650118;020-83650128', 'distance': [], 'biz_ext': {'rating': '4.0', 'cost': '62.00', 'meal_ordering': '0'}, 'pname': '广东省', 'cityname': '广州市', 'adname': '越秀区', 'importance': [], 'shopid': [], 'shopinfo': '0', 'poiweight': [], 'photos': [{'url': 'http://store.is.autonavi.com/showpic/5b7e9d258c4342de4b0ec4ec47a7969b', 'provider': [], 'title': []}, {'url': 'http://store.is.autonavi.com/showpic/c63578165feeddaa0cfb95b8f6c70a3f', 'provider': [], 'title': []}, {'url': 'http://store.is.autonavi.com/showpic/8b49ce6f22ea650e494274144a06691e', 'provider': [], 'title': '香煎年糕'}]}, {'id': 'B0FFG84O3U', 'parent': 'B00140ACA3', 'childtype': '202', 'name': '点都德(中山四路)', 'type': '餐饮服务;快餐厅;茶餐厅', 'typecode': '050305', 'biz_type': 'diner', 'address': '中山四路246号信德大厦5层全层', 'location': '113.271567,23.126007', 'tel': '020-87708336;13632447173', 'distance': [], 'biz_ext': {'rating': '5.0', 'cost': '77.00', 'meal_ordering': '0'}, 'pname': '广东省', 'cityname': '广州市', 'adname': '越秀区', 'importance': [], 'shopid': [], 'shopinfo': '0', 'poiweight': [], 'photos': [{'url': 'http://store.is.autonavi.com/showpic/4053c733c094641052f38ca937b44978', 'provider': [], 'title': []}, {'url': 'http://store.is.autonavi.com/showpic/5380ea4363121e1ac163e48558dc585b', 'provider': [], 'title': '用户'}, {'url': 'http://store.is.autonavi.com/showpic/e6da6dacd3691b2a9bc5f6a3e82b302c', 'provider': [], 'title': '真系菠萝包'}]}, {'id': 'B00140SQ68', 'parent': [], 'childtype': [], 'name': '银记肠粉店(中三分店)', 'type': '餐饮服务;中餐厅;中餐厅', 'typecode': '050100', 'biz_type': 'diner', 'address': '东昌大街3号', 'location': '113.281206,23.126878', 'tel': '020-83883932', 'distance': [], 'biz_ext': {'rating': '3.5', 'cost': '20.00', 'meal_ordering': '0'}, 'pname': '广东省', 'cityname': '广州市', 'adname': '越秀区', 'importance': [], 'shopid': [], 'shopinfo': '0', 'poiweight': [], 'photos': [{'url': 'http://store.is.autonavi.com/showpic/54c3433d4931dff341e0d75b2e5581a1', 'provider': [], 'title': []}, {'url': 'http://store.is.autonavi.com/showpic/7831ae54f31bdc650882717130dec521', 'provider': [], 'title': '菜品'}, {'url': 'http://store.is.autonavi.com/showpic/64f590e04d630ba5a04b805fc4e66597', 'provider': [], 'title': []}]}, {'id': 'B00140NOXA', 'parent': [], 'childtype': [], 'name': '表哥茶餐厅(中三店)(装修中)', 'type': '餐饮服务;快餐厅;茶餐厅', 'typecode': '050305', 'biz_type': 'diner', 'address': '大东街', 'location': '113.280929,23.126913', 'tel': '020-83858360', 'distance': [], 'biz_ext': {'rating': '3.5', 'cost': '49.00', 'meal_ordering': '0'}, 'pname': '广东省', 'cityname': '广州市', 'adname': '越秀区', 'importance': [], 'shopid': [], 'shopinfo': '0', 'poiweight': [], 'photos': [{'url': 'http://store.is.autonavi.com/showpic/a1f3d54adaec4bebca7f97b2b49526d9', 'provider': [], 'title': []}, {'url': 'http://store.is.autonavi.com/showpic/d2660865b7340234adbc3c5b6cddd9bf', 'provider': [], 'title': []}, {'url': 'http://store.is.autonavi.com/showpic/e6774ea5e342629c186084548f7623ac', 'provider': [], 'title': '菜品'}]}, {'id': 'B00140U1MV', 'parent': [], 'childtype': [], 'name': '风味馆(越秀南路店)', 'type': '餐饮服务;中餐厅;中餐厅', 'typecode': '050100', 'biz_type': 'diner', 'address': '越秀南路161号(嘉年华芬兰浴馆对面)', 'location': '113.277423,23.121133', 'tel': '18620913373', 'distance': [], 'biz_ext': {'rating': '3.5', 'cost': '14.00', 'meal_ordering': '0'}, 'pname': '广东省', 'cityname': '广州市', 'adname': '越秀区', 'importance': [], 'shopid': [], 'shopinfo': '0', 'poiweight': [], 'photos': [{'url': 'http://store.is.autonavi.com/showpic/4978cbef14db39b53651aa8ab4b07272', 'provider': [], 'title': []}, {'url': 'http://store.is.autonavi.com/showpic/d90a6d6f7b4cdca440b237114a1652a3', 'provider': [], 'title': []}, {'url': 'http://store.is.autonavi.com/showpic/ae7af300d88abff3836acae450b67a72', 'provider': [], 'title': []}]}, {'id': 'B00141VVZW', 'parent': [], 'childtype': [], 'name': '海底捞火锅(北京路店)(暂停营业)', 'type': '餐饮服务;中餐厅;火锅店', 'typecode': '050117', 'biz_type': 'diner', 'address': '中山四路395号广百黄金珠宝大厦5层', 'location': '113.269638,23.125438', 'tel': '020-83027355;020-83027255', 'distance': [], 'biz_ext': {'rating': '5.0', 'cost': '129.00', 'meal_ordering': '0'}, 'pname': '广东省', 'cityname': '广州市', 'adname': '越秀区', 'importance': [], 'shopid': [], 'shopinfo': '1', 'poiweight': [], 'photos': [{'url': 'http://store.is.autonavi.com/showpic/4446a902fb054044d7052b4616b7323e', 'provider': [], 'title': []}, {'url': 'http://store.is.autonavi.com/showpic/070303011636a54dd30e5dc68a8b3987', 'provider': [], 'title': []}, {'url': 'http://store.is.autonavi.com/showpic/0758536608a5fd09ba467a8db4c143bf', 'provider': [], 'title': []}]}, {'id': 'B0FFHFDUQ1', 'parent': [], 'childtype': [], 'name': '802居酒屋', 'type': '餐饮服务;外国餐厅;外国餐厅', 'typecode': '050200', 'biz_type': 'diner', 'address': '较场东路31号(人民体育场对面)', 'location': '113.284957,23.124104', 'tel': '020-83750421', 'distance': [], 'biz_ext': {'rating': '5.0', 'cost': '252.00', 'meal_ordering': '0'}, 'pname': '广东省', 'cityname': '广州市', 'adname': '越秀区', 'importance': [], 'shopid': [], 'shopinfo': '0', 'poiweight': [], 'photos': [{'url': 'http://store.is.autonavi.com/showpic/768d89e84d012ea48bf7be8f67c4584c', 'provider': [], 'title': []}, {'url': 'http://store.is.autonavi.com/showpic/6e86566ba546f86521bc309fa1b0fc79', 'provider': [], 'title': '菜品'}, {'url': 'http://store.is.autonavi.com/showpic/a24e237941fa791770a4b815dcb92b6e', 'provider': [], 'title': '菜品'}]}, {'id': 'B00140OQ76', 'parent': [], 'childtype': [], 'name': '达扬原味炖品', 'type': '餐饮服务;中餐厅;中餐厅', 'typecode': '050100', 'biz_type': 'diner', 'address': '文明路160号-1号', 'location': '113.274128,23.122562', 'tel': '020-83327931', 'distance': [], 'biz_ext': {'rating': '4.0', 'cost': '20.00', 'meal_ordering': '0'}, 'pname': '广东省', 'cityname': '广州市', 'adname': '越秀区', 'importance': [], 'shopid': [], 'shopinfo': '0', 'poiweight': [], 'photos': [{'url': 'http://store.is.autonavi.com/showpic/85154be41227b59f605860ef4ed0bcf1', 'provider': [], 'title': []}, {'url': 'http://store.is.autonavi.com/showpic/59f1dc57740fd0fad71ff2688c7cdd94', 'provider': [], 'title': []}, {'url': 'http://store.is.autonavi.com/showpic/93b638dfb6b5267cb62a88ac58e7a5bd', 'provider': [], 'title': []}]}, {'id': 'B00140U0SK', 'parent': [], 'childtype': [], 'name': '麦当劳(东川路店)', 'type': '餐饮服务;快餐厅;麦当劳', 'typecode': '050302', 'biz_type': 'diner', 'address': '东川路93号', 'location': '113.286400,23.125176', 'tel': '020-83885037', 'distance': [], 'biz_ext': {'rating': '4.0', 'cost': '28.00', 'meal_ordering': '0'}, 'pname': '广东省', 'cityname': '广州市', 'adname': '越秀区', 'importance': [], 'shopid': [], 'shopinfo': '0', 'poiweight': [], 'photos': [{'url': 'http://store.is.autonavi.com/showpic/d4b12f8b3917891847ee618bb2398ec1', 'provider': [], 'title': []}, {'url': 'http://store.is.autonavi.com/showpic/f147b9af167680497993de16f7d81967', 'provider': [], 'title': []}, {'url': 'http://store.is.autonavi.com/showpic/0e2f5c98a825ae929046f2740b2ed247', 'provider': [], 'title': []}]}, {'id': 'B001402AE9', 'parent': [], 'childtype': [], 'name': '东川酒家(东川路店)', 'type': '餐饮服务;中餐厅;综合酒楼', 'typecode': '050101', 'biz_type': 'diner', 'address': '东川路92号(近东华东路)东川新街市二楼,烈士陵园B3出口', 'location': '113.286567,23.123537', 'tel': '020-83883452;020-83833080', 'distance': [], 'biz_ext': {'rating': '4.2', 'cost': '75.00', 'meal_ordering': '0'}, 'pname': '广东省', 'cityname': '广州市', 'adname': '越秀区', 'importance': [], 'shopid': [], 'shopinfo': '0', 'poiweight': [], 'photos': [{'url': 'http://store.is.autonavi.com/showpic/0f88b4e6269938d8bd9aaf5ff0789e3e', 'provider': [], 'title': []}, {'url': 'http://store.is.autonavi.com/showpic/186175bb553b3805eed1ed18bb4f4988', 'provider': [], 'title': []}, {'url': 'http://store.is.autonavi.com/showpic/ab22687d5b8b4b8d7d89268c664486ea', 'provider': [], 'title': []}]}, {'id': 'B0FFI9RK5B', 'parent': 'B00140BOXP', 'childtype': '202', 'name': '木屋烧烤(越秀地王广场店)', 'type': '餐饮服务;中餐厅;特色/地方风味餐厅', 'typecode': '050118', 'biz_type': 'diner', 'address': '地王广场B1层烈士陵园地铁A出口', 'location': '113.284632,23.125906', 'tel': '020-83028839', 'distance': [], 'biz_ext': {'rating': '4.5', 'cost': '83.00', 'meal_ordering': '0'}, 'pname': '广东省', 'cityname': '广州市', 'adname': '越秀区', 'importance': [], 'shopid': [], 'shopinfo': '1', 'poiweight': [], 'photos': [{'url': 'http://store.is.autonavi.com/showpic/ca3e84b0b73e2298f77edd2f80a6f16b', 'provider': [], 'title': []}, {'url': 'http://store.is.autonavi.com/showpic/0b9e79cc4c6af1559a5d994c744cfbb9', 'provider': [], 'title': '菜品'}, {'url': 'http://store.is.autonavi.com/showpic/47e33e3f587672234f5875f01299df9e', 'provider': [], 'title': '菜品'}]}, {'id': 'B00141VWBN', 'parent': [], 'childtype': [], 'name': '点都德(聚福楼店)', 'type': '餐饮服务;中餐厅;中餐厅', 'typecode': '050100', 'biz_type': 'diner', 'address': '惠福东路470号(富临食府对面)', 'location': '113.265391,23.120475', 'tel': '13632423292;15914213858', 'distance': [], 'biz_ext': {'rating': '4.5', 'cost': '76.00', 'meal_ordering': '0'}, 'pname': '广东省', 'cityname': '广州市', 'adname': '越秀区', 'importance': [], 'shopid': [], 'shopinfo': '0', 'poiweight': [], 'photos': [{'url': 'http://store.is.autonavi.com/showpic/4053c733c094641052f38ca937b44978', 'provider': [], 'title': []}, {'url': 'http://store.is.autonavi.com/showpic/c6a3cd23e673791e086a2198761b4742', 'provider': [], 'title': '环境'}, {'url': 'http://store.is.autonavi.com/showpic/9bcc92877dbdfe13b668bed9233aec8b', 'provider': [], 'title': []}]}, {'id': 'B00141L0QR', 'parent': [], 'childtype': [], 'name': '禄鼎记(建六店)', 'type': '餐饮服务;中餐厅;四川菜(川菜)', 'typecode': '050102', 'biz_type': 'diner', 'address': '建设六马路1号前幢3层A号', 'location': '113.284914,23.131437', 'tel': '020-83882625', 'distance': [], 'biz_ext': {'rating': '4.5', 'cost': '96.00', 'meal_ordering': '0'}, 'pname': '广东省', 'cityname': '广州市', 'adname': '越秀区', 'importance': [], 'shopid': [], 'shopinfo': '0', 'poiweight': [], 'photos': [{'url': 'http://store.is.autonavi.com/showpic/1e826bcb558289d7bcb37555a0634f3c', 'provider': [], 'title': []}, {'url': 'http://store.is.autonavi.com/showpic/4b868ea1bd946a9a41086de97f374aa4', 'provider': [], 'title': []}, {'url': 'http://store.is.autonavi.com/showpic/563e9cbad45860efc867a35e507b9879', 'provider': [], 'title': []}]}, {'id': 'B00140D2WB', 'parent': [], 'childtype': [], 'name': '永盈茶餐厅(中山四路店)', 'type': '餐饮服务;快餐厅;茶餐厅', 'typecode': '050305', 'biz_type': 'diner', 'address': '中山四路130号(近农讲所)', 'location': '113.274280,23.126702', 'tel': '020-83303519;020-83371975', 'distance': [], 'biz_ext': {'rating': '3.5', 'cost': '40.00', 'meal_ordering': '0'}, 'pname': '广东省', 'cityname': '广州市', 'adname': '越秀区', 'importance': [], 'shopid': [], 'shopinfo': '0', 'poiweight': [], 'photos': [{'url': 'http://store.is.autonavi.com/showpic/23077a04d57ea4ef377570bc3ab9481c', 'provider': [], 'title': []}, {'url': 'http://store.is.autonavi.com/showpic/8d1f0d77860e5fd5ccb4677c09323b5b', 'provider': [], 'title': []}, {'url': 'http://store.is.autonavi.com/showpic/d39db541ec41d8b650805b4264e60db9', 'provider': [], 'title': '菜品'}]}, {'id': 'B00140T2CY', 'parent': 'B00140BUT7', 'childtype': '201', 'name': '利苑酒家(宜安广场)', 'type': '餐饮服务;中餐厅;广东菜(粤菜)|住宿服务;宾馆酒店;宾馆酒店', 'typecode': '050103|100100', 'biz_type': 'diner', 'address': '建设六马路33号宜安广场F4层', 'location': '113.284896,23.134419', 'tel': '020-83633268', 'distance': [], 'biz_ext': {'rating': '5.0', 'cost': '273.00', 'hotel_ordering': [], 'meal_ordering': '0', 'star': [], 'lowest_price': []}, 'pname': '广东省', 'cityname': '广州市', 'adname': '越秀区', 'importance': [], 'shopid': [], 'shopinfo': '0', 'poiweight': [], 'photos': [{'url': 'http://store.is.autonavi.com/showpic/8f9b3c348199440d240372bfb1b6e441', 'provider': [], 'title': []}, {'url': 'http://store.is.autonavi.com/showpic/2c993af2dcc7a80679a293e9af0ee2e3', 'provider': [], 'title': []}, {'url': 'http://store.is.autonavi.com/showpic/9a5b9346b4f4463642b0848d99d2dde5', 'provider': [], 'title': []}]}, {'id': 'B00140SDNV', 'parent': 'B00140I1A9', 'childtype': '202', 'name': '一品柠檬鱼(中山三路店)', 'type': '餐饮服务;中餐厅;中餐厅', 'typecode': '050100', 'biz_type': 'diner', 'address': '中山三路36号威力达大厦3层', 'location': '113.281958,23.127184', 'tel': '18102228070;020-83765803', 'distance': [], 'biz_ext': {'rating': '3.5', 'cost': '74.00', 'meal_ordering': '0'}, 'pname': '广东省', 'cityname': '广州市', 'adname': '越秀区', 'importance': [], 'shopid': [], 'shopinfo': '0', 'poiweight': [], 'photos': [{'url': 'http://store.is.autonavi.com/showpic/7578e9cca6044b33acb77c08a106611a', 'provider': [], 'title': []}, {'url': 'http://store.is.autonavi.com/showpic/ab9526a559a3eb8492666b1abb2fa376', 'provider': [], 'title': []}, {'url': 'http://store.is.autonavi.com/showpic/07e0c578205afd9bb1fc6340420252f9', 'provider': [], 'title': []}]}, {'id': 'B0FFF0FKTH', 'parent': 'B00140AG0N', 'childtype': '201', 'name': '1928音乐餐厅(五月花商业广场)', 'type': '餐饮服务;外国餐厅;法式菜品餐厅', 'typecode': '050204', 'biz_type': 'diner', 'address': '中山五路68号五月花商业广场F4层416-418/423', 'location': '113.266741,23.125820', 'tel': '020-83333810', 'distance': [], 'biz_ext': {'rating': '4.0', 'cost': '78.00', 'meal_ordering': '0'}, 'pname': '广东省', 'cityname': '广州市', 'adname': '越秀区', 'importance': [], 'shopid': [], 'shopinfo': '0', 'poiweight': [], 'photos': [{'url': 'http://store.is.autonavi.com/showpic/e9d1570c9b70fe736489810742a36028', 'provider': [], 'title': []}, {'url': 'http://store.is.autonavi.com/showpic/0f9c57fcb2c883d46b51dd81081a4226', 'provider': [], 'title': '菜品'}, {'url': 'http://store.is.autonavi.com/showpic/c7cedd38355525e37b0ef2683e6460db', 'provider': [], 'title': '菜品'}]}, {'id': 'B00140V9RJ', 'parent': 'B00140U0SG', 'childtype': '201', 'name': '大椰丰饭(中华店)', 'type': '餐饮服务;中餐厅;综合酒楼', 'typecode': '050101', 'biz_type': 'diner', 'address': '中山三路33号中华广场6F层6051/6055', 'location': '113.282137,23.125361', 'tel': '020-83738588;020-83738088', 'distance': [], 'biz_ext': {'rating': '3.0', 'cost': '107.00', 'meal_ordering': '0'}, 'pname': '广东省', 'cityname': '广州市', 'adname': '越秀区', 'importance': [], 'shopid': [], 'shopinfo': '0', 'poiweight': [], 'photos': [{'url': 'http://store.is.autonavi.com/showpic/1a316abfa5829456d7fa5674037edd84', 'provider': [], 'title': []}, {'url': 'http://store.is.autonavi.com/showpic/21c5f75296888ee6386ba16ecb180f22', 'provider': [], 'title': '菜品'}, {'url': 'http://store.is.autonavi.com/showpic/8568c05042a262f2c9fa73d0f36797bc', 'provider': [], 'title': []}]}]}\n"
     ]
    }
   ],
   "source": [
    "# 搜索广东美食\n",
    "示例_b = search_poi(keywords=\"美食\",city='广东')\n",
    "print(示例_b)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "* 背后功能：数据挖掘"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# ip定位"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "* 希望能够将IP信息转换为地理位置信息。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 74,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "192.168.137.1\n"
     ]
    }
   ],
   "source": [
    "# 获取自己的本地ip\n",
    "import socket\n",
    "# 获取本机计算机名称\n",
    "hostname = socket.gethostname()\n",
    "# 获取本机ip\n",
    "ip = socket.gethostbyname(hostname)\n",
    "print(ip)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 75,
   "metadata": {},
   "outputs": [],
   "source": [
    "def ip_location(ip,sig=None)->dict:\n",
    "    url = 'https://restapi.amap.com/v3/ip?parameters'\n",
    "    params = {\n",
    "        'key': key_lin,\n",
    "        'ip': ip,\n",
    "        'sig': sig,\n",
    "        'output': 'json'\n",
    "    }\n",
    "    response = requests.get(url,params=params)\n",
    "    data = response.json()\n",
    "    return data"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 76,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'status': '1', 'info': 'OK', 'infocode': '10000', 'province': '局域网', 'city': [], 'adcode': [], 'rectangle': []}\n"
     ]
    }
   ],
   "source": [
    "示例_c = ip_location(ip='192.168.137.1')\n",
    "print(示例_c)\n",
    "# ???"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "* 背后功能：信息检索"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 批量请求接口"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "* 希望批量得到接口返回数据的用户。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 77,
   "metadata": {},
   "outputs": [],
   "source": [
    "import requests\n",
    "\n",
    "url=\"https://restapi.amap.com/v3/batch?key=\" + key_lin\n",
    "\n",
    "def piliang():\n",
    "    header={\n",
    "                'Connection':'close',\n",
    "                'Accept':'application/json,image/gif, image/jpeg, image/pjpeg, image/pjpeg, application/x-shockwave-flash, */*',\n",
    "                'User-Agent':'Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; .NET CLR 2.0.50727)',\n",
    "                \"Content-Type\": \"application/json; charset=UTF-8\"\n",
    "    }\n",
    "    body={\n",
    "            \"ops\": [\n",
    "            {\n",
    "                \"url\": \"/v3/place/around?offset=10&page=1&key=7347a7fce48d28ebeafa2256c9dfc189&location=116.50394379585519,39.278209477408794&output=json&radius=100000&types=080000\"\n",
    "            },\n",
    "            {\n",
    "                \"url\": \"/v3/place/around?offset=10&page=1&key=7347a7fce48d28ebeafa2256c9dfc189&location=118.50394379585519,39.278209477408794&output=json&radius=100000&types=080000\"\n",
    "            }\n",
    "        ]\n",
    "    }\n",
    "    r=requests.post(url,json=body).json()\n",
    "    return r"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 78,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[{'status': 200,\n",
       "  'body': {'suggestion': {'keywords': {}, 'cities': {}},\n",
       "   'info': 'OK',\n",
       "   'status': '1',\n",
       "   'count': '888',\n",
       "   'pois': [{'typecode': '080000',\n",
       "     'adname': '永清县',\n",
       "     'biz_type': {},\n",
       "     'id': 'B0FFKKSDDS',\n",
       "     'pname': '河北省',\n",
       "     'importance': {},\n",
       "     'parent': {},\n",
       "     'location': '116.511528,39.270463',\n",
       "     'distance': '1082',\n",
       "     'tel': {},\n",
       "     'biz_ext': {'rating': {}, 'cost': {}},\n",
       "     'shopid': {},\n",
       "     'address': {},\n",
       "     'poiweight': {},\n",
       "     'cityname': '廊坊市',\n",
       "     'photos': {},\n",
       "     'type': '体育休闲服务;体育休闲服务场所;体育休闲服务场所',\n",
       "     'shopinfo': '0',\n",
       "     'name': '李庄子村兰阳草莓采摘园',\n",
       "     'childtype': {}},\n",
       "    {'typecode': '080501',\n",
       "     'adname': '永清县',\n",
       "     'biz_type': {},\n",
       "     'id': 'B0FFJM772Z',\n",
       "     'pname': '河北省',\n",
       "     'importance': {},\n",
       "     'parent': {},\n",
       "     'location': '116.513958,39.270648',\n",
       "     'distance': '1205',\n",
       "     'tel': {},\n",
       "     'biz_ext': {'rating': {}, 'cost': {}},\n",
       "     'shopid': {},\n",
       "     'address': '永清镇北辛溜附近',\n",
       "     'poiweight': {},\n",
       "     'cityname': '廊坊市',\n",
       "     'photos': {},\n",
       "     'type': '体育休闲服务;休闲场所;游乐场',\n",
       "     'shopinfo': '0',\n",
       "     'name': '儿童乐园',\n",
       "     'childtype': {}},\n",
       "    {'typecode': '080503',\n",
       "     'adname': '永清县',\n",
       "     'biz_type': {},\n",
       "     'id': 'B013C16BMA',\n",
       "     'pname': '河北省',\n",
       "     'importance': {},\n",
       "     'parent': {},\n",
       "     'location': '116.480285,39.291357',\n",
       "     'distance': '2509',\n",
       "     'tel': '13363650160',\n",
       "     'biz_ext': {'rating': {}, 'cost': {}},\n",
       "     'shopid': {},\n",
       "     'address': '永金一桥东500米',\n",
       "     'poiweight': {},\n",
       "     'cityname': '廊坊市',\n",
       "     'photos': [{'url': 'http://store.is.autonavi.com/showpic/3e517731940c4684ee94acdfb8c39b26',\n",
       "       'title': {},\n",
       "       'provider': {}},\n",
       "      {'url': 'http://store.is.autonavi.com/showpic/8eb4c3eb92489cb32cafa17205dc0112',\n",
       "       'title': {},\n",
       "       'provider': {}},\n",
       "      {'url': 'http://store.is.autonavi.com/showpic/163f3273c7c60016197a2e7912df53df',\n",
       "       'title': {},\n",
       "       'provider': {}}],\n",
       "     'type': '体育休闲服务;休闲场所;采摘园',\n",
       "     'shopinfo': '0',\n",
       "     'name': '开心草莓采摘园',\n",
       "     'childtype': {}},\n",
       "    {'typecode': '080501',\n",
       "     'adname': '永清县',\n",
       "     'biz_type': {},\n",
       "     'id': 'B0FFLPYFW5',\n",
       "     'pname': '河北省',\n",
       "     'importance': {},\n",
       "     'parent': {},\n",
       "     'location': '116.496816,39.302615',\n",
       "     'distance': '2785',\n",
       "     'tel': {},\n",
       "     'biz_ext': {'rating': {}, 'cost': {}},\n",
       "     'shopid': {},\n",
       "     'address': '益昌南路225东北100米',\n",
       "     'poiweight': {},\n",
       "     'cityname': '廊坊市',\n",
       "     'photos': {},\n",
       "     'type': '体育休闲服务;休闲场所;游乐场',\n",
       "     'shopinfo': '0',\n",
       "     'name': 'DIY儿童乐园',\n",
       "     'childtype': {}},\n",
       "    {'typecode': '080603',\n",
       "     'adname': '永清县',\n",
       "     'biz_type': {},\n",
       "     'id': 'B0FFLAIP6H',\n",
       "     'pname': '河北省',\n",
       "     'importance': {},\n",
       "     'parent': {},\n",
       "     'location': '116.496230,39.303248',\n",
       "     'distance': '2865',\n",
       "     'tel': {},\n",
       "     'biz_ext': {'seat_ordering': '0', 'rating': {}, 'cost': {}},\n",
       "     'shopid': {},\n",
       "     'address': '益昌南路',\n",
       "     'poiweight': {},\n",
       "     'cityname': '廊坊市',\n",
       "     'photos': {},\n",
       "     'type': '体育休闲服务;影剧院;剧场',\n",
       "     'shopinfo': '0',\n",
       "     'name': '向阳禾理想城梦剧场',\n",
       "     'childtype': {}},\n",
       "    {'typecode': '080308',\n",
       "     'adname': '永清县',\n",
       "     'biz_type': {},\n",
       "     'id': 'B013C0IMLS',\n",
       "     'pname': '河北省',\n",
       "     'importance': {},\n",
       "     'parent': {},\n",
       "     'location': '116.496593,39.304251',\n",
       "     'distance': '2967',\n",
       "     'tel': {},\n",
       "     'biz_ext': {'rating': '3.5', 'cost': {}},\n",
       "     'shopid': {},\n",
       "     'address': '益昌南路179号',\n",
       "     'poiweight': {},\n",
       "     'cityname': '廊坊市',\n",
       "     'photos': [{'url': 'http://store.is.autonavi.com/showpic/af47a5f4f741f6a3ad170e226f856b92',\n",
       "       'title': {},\n",
       "       'provider': {}}],\n",
       "     'type': '体育休闲服务;娱乐场所;网吧',\n",
       "     'shopinfo': '0',\n",
       "     'name': '梦想网吧(益昌南路店)',\n",
       "     'childtype': {}},\n",
       "    {'typecode': '080119',\n",
       "     'adname': '永清县',\n",
       "     'biz_type': {},\n",
       "     'id': 'B0FFMDQ6D7',\n",
       "     'pname': '河北省',\n",
       "     'importance': {},\n",
       "     'parent': {},\n",
       "     'location': '116.493187,39.304274',\n",
       "     'distance': '3045',\n",
       "     'tel': '13141201944',\n",
       "     'biz_ext': {'rating': {}, 'cost': {}},\n",
       "     'shopid': {},\n",
       "     'address': '武隆南路宏益街',\n",
       "     'poiweight': {},\n",
       "     'cityname': '廊坊市',\n",
       "     'photos': [{'url': 'http://store.is.autonavi.com/showpic/0fb1662d06ad761b51070fe0ca4c26c5',\n",
       "       'title': {},\n",
       "       'provider': {}}],\n",
       "     'type': '体育休闲服务;运动场馆;跆拳道场馆',\n",
       "     'shopinfo': '1',\n",
       "     'name': '龙圣跆拳道馆',\n",
       "     'childtype': {}},\n",
       "    {'typecode': '080000',\n",
       "     'adname': '永清县',\n",
       "     'biz_type': {},\n",
       "     'id': 'B0FFJQZNZW',\n",
       "     'pname': '河北省',\n",
       "     'importance': {},\n",
       "     'parent': {},\n",
       "     'location': '116.497741,39.309459',\n",
       "     'distance': '3519',\n",
       "     'tel': '15210485655',\n",
       "     'biz_ext': {'rating': {}, 'cost': {}},\n",
       "     'shopid': {},\n",
       "     'address': '益昌南路268号新旺小区门口',\n",
       "     'poiweight': {},\n",
       "     'cityname': '廊坊市',\n",
       "     'photos': [{'url': 'http://store.is.autonavi.com/showpic/67416ad37c69db61c270016fa6f430cc',\n",
       "       'title': {},\n",
       "       'provider': {}},\n",
       "      {'url': 'http://store.is.autonavi.com/showpic/d89fd2e7d4b62cba6187c87cc838bb89',\n",
       "       'title': {},\n",
       "       'provider': {}},\n",
       "      {'url': 'http://store.is.autonavi.com/showpic/dbaae4d6ace1004675ce4f252088ffe6',\n",
       "       'title': {},\n",
       "       'provider': {}}],\n",
       "     'type': '体育休闲服务;体育休闲服务场所;体育休闲服务场所',\n",
       "     'shopinfo': '1',\n",
       "     'name': '熙瑞国际游泳健身会所',\n",
       "     'childtype': {}},\n",
       "    {'typecode': '080113',\n",
       "     'adname': '永清县',\n",
       "     'biz_type': {},\n",
       "     'id': 'B0FFM4EHTE',\n",
       "     'pname': '河北省',\n",
       "     'importance': {},\n",
       "     'parent': {},\n",
       "     'location': '116.495838,39.309940',\n",
       "     'distance': '3600',\n",
       "     'tel': {},\n",
       "     'biz_ext': {'rating': {}, 'cost': {}},\n",
       "     'shopid': {},\n",
       "     'address': {},\n",
       "     'poiweight': {},\n",
       "     'cityname': '廊坊市',\n",
       "     'photos': {},\n",
       "     'type': '体育休闲服务;运动场馆;台球厅',\n",
       "     'shopinfo': '0',\n",
       "     'name': 'K9台球',\n",
       "     'childtype': {}},\n",
       "    {'typecode': '080308',\n",
       "     'adname': '永清县',\n",
       "     'biz_type': {},\n",
       "     'id': 'B0FFJKVFLQ',\n",
       "     'pname': '河北省',\n",
       "     'importance': {},\n",
       "     'parent': {},\n",
       "     'location': '116.497249,39.310649',\n",
       "     'distance': '3656',\n",
       "     'tel': {},\n",
       "     'biz_ext': {'rating': {}, 'cost': {}},\n",
       "     'shopid': {},\n",
       "     'address': '益昌中路与益昌南路交叉口西南50米',\n",
       "     'poiweight': {},\n",
       "     'cityname': '廊坊市',\n",
       "     'photos': {},\n",
       "     'type': '体育休闲服务;娱乐场所;网吧',\n",
       "     'shopinfo': '0',\n",
       "     'name': '网咖',\n",
       "     'childtype': {}}],\n",
       "   'infocode': '10000'},\n",
       "  'header': {'gsid': '011137148108158762231853400019635346832',\n",
       "   'Vary': 'Accept-Encoding',\n",
       "   'Content-Type': 'application/json;charset=UTF-8',\n",
       "   'Access-Control-Allow-Methods': '*',\n",
       "   'Access-Control-Allow-Origin': '*',\n",
       "   'sc': '0.138',\n",
       "   'Content-Length': 5294,\n",
       "   'Access-Control-Allow-Headers': 'DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,key,x-biz,x-info,platinfo,encr,enginever,gzipped,poiid',\n",
       "   'X-Powered-By': 'ring/1.0.0'}},\n",
       " {'status': 200,\n",
       "  'body': {'suggestion': {'keywords': {}, 'cities': {}},\n",
       "   'info': 'OK',\n",
       "   'status': '1',\n",
       "   'count': '876',\n",
       "   'pois': [{'typecode': '080000',\n",
       "     'adname': '曹妃甸区',\n",
       "     'biz_type': {},\n",
       "     'id': 'B0FFIT4V37',\n",
       "     'pname': '河北省',\n",
       "     'importance': {},\n",
       "     'parent': {},\n",
       "     'location': '118.509300,39.261324',\n",
       "     'distance': '1935',\n",
       "     'tel': {},\n",
       "     'biz_ext': {'rating': {}, 'cost': {}},\n",
       "     'shopid': {},\n",
       "     'address': '昌丰路与昌盛街交叉口东150米',\n",
       "     'poiweight': {},\n",
       "     'cityname': '唐山市',\n",
       "     'photos': {},\n",
       "     'type': '体育休闲服务;体育休闲服务场所;体育休闲服务场所',\n",
       "     'shopinfo': '0',\n",
       "     'name': '利民老年公寓',\n",
       "     'childtype': {}},\n",
       "    {'typecode': '080500',\n",
       "     'adname': '曹妃甸区',\n",
       "     'biz_type': {},\n",
       "     'id': 'B0FFM1WN4Q',\n",
       "     'pname': '河北省',\n",
       "     'importance': {},\n",
       "     'parent': {},\n",
       "     'location': '118.473800,39.284305',\n",
       "     'distance': '2684',\n",
       "     'tel': '13102692203;15032998415',\n",
       "     'biz_ext': {'rating': {}, 'cost': {}},\n",
       "     'shopid': {},\n",
       "     'address': '永丰路与建设大街交叉口北行200米再东行200米',\n",
       "     'poiweight': {},\n",
       "     'cityname': '唐山市',\n",
       "     'photos': [{'url': 'http://store.is.autonavi.com/showpic/02f9a9353f15bb7c882c281addaca79a',\n",
       "       'title': {},\n",
       "       'provider': {}},\n",
       "      {'url': 'http://store.is.autonavi.com/showpic/462da2324343c04c255e5b6b55403952',\n",
       "       'title': {},\n",
       "       'provider': {}},\n",
       "      {'url': 'http://store.is.autonavi.com/showpic/dfc87db906b2994dae80342d4563b1e9',\n",
       "       'title': {},\n",
       "       'provider': {}}],\n",
       "     'type': '体育休闲服务;休闲场所;休闲场所',\n",
       "     'shopinfo': '1',\n",
       "     'name': '唐山兵途枪战运动',\n",
       "     'childtype': {}},\n",
       "    {'typecode': '080301',\n",
       "     'adname': '曹妃甸区',\n",
       "     'biz_type': {},\n",
       "     'id': 'B0FFF2T193',\n",
       "     'pname': '河北省',\n",
       "     'importance': {},\n",
       "     'parent': {},\n",
       "     'location': '118.471098,39.281979',\n",
       "     'distance': '2861',\n",
       "     'tel': '0315-8037777',\n",
       "     'biz_ext': {'rating': '4.3', 'cost': {}},\n",
       "     'shopid': {},\n",
       "     'address': '建设大街与永丰路交叉口西南角',\n",
       "     'poiweight': {},\n",
       "     'cityname': '唐山市',\n",
       "     'photos': [{'url': 'http://store.is.autonavi.com/showpic/c8fd0a18befbe849ce8df7908d88ed24',\n",
       "       'title': {},\n",
       "       'provider': {}},\n",
       "      {'url': 'http://store.is.autonavi.com/showpic/468baaf5453e6c1b38d0c4c417183b40',\n",
       "       'title': {},\n",
       "       'provider': {}},\n",
       "      {'url': 'http://store.is.autonavi.com/showpic/a0a5fff0b63e60b3508c2ecb197d07e5',\n",
       "       'title': {},\n",
       "       'provider': {}}],\n",
       "     'type': '体育休闲服务;娱乐场所;夜总会',\n",
       "     'shopinfo': '0',\n",
       "     'name': '一代佳人夜总会',\n",
       "     'childtype': {}},\n",
       "    {'typecode': '080000',\n",
       "     'adname': '曹妃甸区',\n",
       "     'biz_type': {},\n",
       "     'id': 'B0FFKPS8TZ',\n",
       "     'pname': '河北省',\n",
       "     'importance': {},\n",
       "     'parent': {},\n",
       "     'location': '118.471344,39.273170',\n",
       "     'distance': '2864',\n",
       "     'tel': {},\n",
       "     'biz_ext': {'rating': {}, 'cost': {}},\n",
       "     'shopid': {},\n",
       "     'address': '垦丰大街与永丰路交叉口南50米',\n",
       "     'poiweight': {},\n",
       "     'cityname': '唐山市',\n",
       "     'photos': {},\n",
       "     'type': '体育休闲服务;体育休闲服务场所;体育休闲服务场所',\n",
       "     'shopinfo': '0',\n",
       "     'name': '新少年跆拳道馆',\n",
       "     'childtype': {}},\n",
       "    {'typecode': '080402',\n",
       "     'adname': '曹妃甸区',\n",
       "     'biz_type': {},\n",
       "     'id': 'B013B031EO',\n",
       "     'pname': '河北省',\n",
       "     'importance': {},\n",
       "     'parent': {},\n",
       "     'location': '118.469256,39.278622',\n",
       "     'distance': '2989',\n",
       "     'tel': {},\n",
       "     'biz_ext': {'rating': {}, 'cost': {}},\n",
       "     'shopid': {},\n",
       "     'address': '曙光街23号',\n",
       "     'poiweight': {},\n",
       "     'cityname': '唐山市',\n",
       "     'photos': {},\n",
       "     'type': '体育休闲服务;度假疗养场所;疗养院',\n",
       "     'shopinfo': '0',\n",
       "     'name': '光荣院(曙光街)',\n",
       "     'childtype': {}},\n",
       "    {'typecode': '080500',\n",
       "     'adname': '曹妃甸区',\n",
       "     'biz_type': {},\n",
       "     'id': 'B0FFHF91Y9',\n",
       "     'pname': '河北省',\n",
       "     'importance': {},\n",
       "     'parent': {},\n",
       "     'location': '118.467429,39.273141',\n",
       "     'distance': '3196',\n",
       "     'tel': {},\n",
       "     'biz_ext': {'rating': {}, 'cost': {}},\n",
       "     'shopid': {},\n",
       "     'address': '垦丰大街8号',\n",
       "     'poiweight': {},\n",
       "     'cityname': '唐山市',\n",
       "     'photos': {},\n",
       "     'type': '体育休闲服务;休闲场所;休闲场所',\n",
       "     'shopinfo': '0',\n",
       "     'name': '曹妃甸区老干部活动中心',\n",
       "     'childtype': {}},\n",
       "    {'typecode': '080119',\n",
       "     'adname': '曹妃甸区',\n",
       "     'biz_type': {},\n",
       "     'id': 'B0FFLDK6TP',\n",
       "     'pname': '河北省',\n",
       "     'importance': {},\n",
       "     'parent': {},\n",
       "     'location': '118.466867,39.281969',\n",
       "     'distance': '3222',\n",
       "     'tel': '17736580504',\n",
       "     'biz_ext': {'rating': {}, 'cost': {}},\n",
       "     'shopid': {},\n",
       "     'address': '建设大街红赫世家东底商58号',\n",
       "     'poiweight': {},\n",
       "     'cityname': '唐山市',\n",
       "     'photos': [{'url': 'http://store.is.autonavi.com/showpic/b59e23956de23e47401416a6b4808c0c',\n",
       "       'title': {},\n",
       "       'provider': {}}],\n",
       "     'type': '体育休闲服务;运动场馆;跆拳道场馆',\n",
       "     'shopinfo': '0',\n",
       "     'name': '泽仁跆拳道',\n",
       "     'childtype': {}},\n",
       "    {'typecode': '080000',\n",
       "     'adname': '滦南县',\n",
       "     'biz_type': {},\n",
       "     'id': 'B0FFH9MB8R',\n",
       "     'pname': '河北省',\n",
       "     'importance': {},\n",
       "     'parent': {},\n",
       "     'location': '118.527757,39.301926',\n",
       "     'distance': '3343',\n",
       "     'tel': {},\n",
       "     'biz_ext': {'rating': {}, 'cost': {}},\n",
       "     'shopid': {},\n",
       "     'address': '杨柏线北50米',\n",
       "     'poiweight': {},\n",
       "     'cityname': '唐山市',\n",
       "     'photos': {},\n",
       "     'type': '体育休闲服务;体育休闲服务场所;体育休闲服务场所',\n",
       "     'shopinfo': '0',\n",
       "     'name': '陶乐宝儿童乐园',\n",
       "     'childtype': {}},\n",
       "    {'typecode': '080304',\n",
       "     'adname': '曹妃甸区',\n",
       "     'biz_type': {},\n",
       "     'id': 'B0FFLOR4DN',\n",
       "     'pname': '河北省',\n",
       "     'importance': {},\n",
       "     'parent': {},\n",
       "     'location': '118.466494,39.287701',\n",
       "     'distance': '3395',\n",
       "     'tel': {},\n",
       "     'biz_ext': {'rating': {}, 'cost': {}},\n",
       "     'shopid': {},\n",
       "     'address': '青年城二期东底商24号',\n",
       "     'poiweight': {},\n",
       "     'cityname': '唐山市',\n",
       "     'photos': [{'url': 'http://store.is.autonavi.com/showpic/29997dd7b0c66b1dc6f15a253918ccf2',\n",
       "       'title': {},\n",
       "       'provider': {}},\n",
       "      {'url': 'http://store.is.autonavi.com/showpic/098df33a76f03e8d55672683f63da5d8',\n",
       "       'title': {},\n",
       "       'provider': {}}],\n",
       "     'type': '体育休闲服务;娱乐场所;酒吧',\n",
       "     'shopinfo': '1',\n",
       "     'name': 'ELK酒吧',\n",
       "     'childtype': {}},\n",
       "    {'typecode': '080113',\n",
       "     'adname': '滦南县',\n",
       "     'biz_type': {},\n",
       "     'id': 'B0FFMB6BAG',\n",
       "     'pname': '河北省',\n",
       "     'importance': {},\n",
       "     'parent': {},\n",
       "     'location': '118.528670,39.302678',\n",
       "     'distance': '3457',\n",
       "     'tel': {},\n",
       "     'biz_ext': {'rating': {}, 'cost': {}},\n",
       "     'shopid': {},\n",
       "     'address': {},\n",
       "     'poiweight': {},\n",
       "     'cityname': '唐山市',\n",
       "     'photos': {},\n",
       "     'type': '体育休闲服务;运动场馆;台球厅',\n",
       "     'shopinfo': '0',\n",
       "     'name': '下午时光台球俱乐部',\n",
       "     'childtype': {}}],\n",
       "   'infocode': '10000'},\n",
       "  'header': {'gsid': '011137148108158762231853400019635346832',\n",
       "   'Vary': 'Accept-Encoding',\n",
       "   'Content-Type': 'application/json;charset=UTF-8',\n",
       "   'Access-Control-Allow-Methods': '*',\n",
       "   'Access-Control-Allow-Origin': '*',\n",
       "   'sc': '0.162',\n",
       "   'Content-Length': 5564,\n",
       "   'Access-Control-Allow-Headers': 'DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,key,x-biz,x-info,platinfo,encr,enginever,gzipped,poiid',\n",
       "   'X-Powered-By': 'ring/1.0.0'}}]"
      ]
     },
     "execution_count": 78,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "piliang()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "* 背后功能：信息检索"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 静态地图"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "* 静态地图服务通过返回一张地图图片响应HTTP请求，使用户能够将高德地图以图片形式嵌入自己的网页中。用户可以指定请求的地图位置、图片大小、以及在地图上添加覆盖物，如标签、标注、折线、多边形。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 79,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "中大南方地理编码: 113.679287,23.632575\n"
     ]
    }
   ],
   "source": [
    "# 获取location\n",
    "print(\"中大南方地理编码:\",中大南方地理编码)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 80,
   "metadata": {},
   "outputs": [],
   "source": [
    "#  scale=None,traffic=None,\n",
    "def static_map(location,size,sig=None)->dict:   \n",
    "    url = 'https://restapi.amap.com/v3/staticmap?'\n",
    "    params = {\n",
    "        'key': key_lin,\n",
    "        'location': location,\n",
    "        'size': size,\n",
    "        'sig': sig,\n",
    "    }\n",
    "    url_map = url + 'location='+location + '&size='+ size + '&markers=mid,,'+'A:'+location+'&key='+ key_lin\n",
    "    return url_map"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 81,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "https://restapi.amap.com/v3/staticmap?location=113.679287,23.632575&size=750*300&markers=mid,,A:113.679287,23.632575&key=131427e6733a34a09c06e84d7905b23d\n"
     ]
    }
   ],
   "source": [
    "示例_d = static_map(location='113.679287,23.632575',size='750*300')\n",
    "print(示例_d)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "![](https://restapi.amap.com/v3/staticmap?location=113.679287,23.632575&size=750*300&markers=mid,,A:113.679287,23.632575&key=131427e6733a34a09c06e84d7905b23d)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "* 背后功能：可视化"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 坐标转换"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "* 为了使用高德服务，用户需要将非高德坐标转换为高德坐标。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 82,
   "metadata": {},
   "outputs": [],
   "source": [
    "def location_trans(locations,coordsys,sig=None)->dict:\n",
    "    url = 'https://restapi.amap.com/v3/assistant/coordinate/convert?parameters'\n",
    "    params = {\n",
    "        'key': key_lin,\n",
    "        'locations': locations,\n",
    "        'coordsys': coordsys,\n",
    "        'sig': sig,\n",
    "        'output': 'json'\n",
    "    }\n",
    "    response = requests.get(url,params=params)\n",
    "    data = response.json()\n",
    "    return data"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 83,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'status': '1', 'info': 'ok', 'infocode': '10000', 'locations': '113.684476996528,23.629904513889'}\n"
     ]
    }
   ],
   "source": [
    "示例_lt = location_trans(locations='113.679287,23.632575',coordsys='gps')\n",
    "print(示例_lt)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "* 背后功能：自然语言处理、机器学习"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 天气查询"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 84,
   "metadata": {},
   "outputs": [],
   "source": [
    "def search_weather(city,extensions='all')->dict:\n",
    "    url = 'https://restapi.amap.com/v3/weather/weatherInfo?parameters'\n",
    "    params={\n",
    "        'key':key_lin,\n",
    "        'city': city,\n",
    "        'output':'json',\n",
    "    }\n",
    "    response = requests.get(url,params=params)\n",
    "    data = response.json()\n",
    "    return data"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 85,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'status': '1', 'count': '1', 'info': 'OK', 'infocode': '10000', 'lives': [{'province': '广东', 'city': '汕头市', 'adcode': '440500', 'weather': '阴', 'temperature': '19', 'winddirection': '东', 'windpower': '≤3', 'humidity': '70', 'reporttime': '2020-04-23 13:52:34'}]}\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>province</th>\n",
       "      <th>city</th>\n",
       "      <th>adcode</th>\n",
       "      <th>weather</th>\n",
       "      <th>temperature</th>\n",
       "      <th>winddirection</th>\n",
       "      <th>windpower</th>\n",
       "      <th>humidity</th>\n",
       "      <th>reporttime</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>广东</td>\n",
       "      <td>汕头市</td>\n",
       "      <td>440500</td>\n",
       "      <td>阴</td>\n",
       "      <td>19</td>\n",
       "      <td>东</td>\n",
       "      <td>≤3</td>\n",
       "      <td>70</td>\n",
       "      <td>2020-04-23 13:52:34</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "  province city  adcode weather temperature winddirection windpower humidity  \\\n",
       "0       广东  汕头市  440500       阴          19             东        ≤3       70   \n",
       "\n",
       "            reporttime  \n",
       "0  2020-04-23 13:52:34  "
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "# 查询汕头天气\n",
    "汕头_weather = search_weather(city='汕头')\n",
    "print(汕头_weather)\n",
    "df_汕头天气预报 = pd.json_normalize(汕头_weather['lives'])\n",
    "display(df_汕头天气预报)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "* 背后功能：信息检索"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 输入提示"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "* 在高德客户端的使用场景，输入“仙林”之后出现提示相关。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 86,
   "metadata": {},
   "outputs": [],
   "source": [
    "def input_pro(keywords,city,datatype='all',sig=None)->dict:\n",
    "    url = 'https://restapi.amap.com/v3/assistant/inputtips?parameters'\n",
    "    params={\n",
    "        'key':key_lin,\n",
    "        'keywords': keywords,\n",
    "        'city': city,\n",
    "        'output':'json',\n",
    "    }\n",
    "    response = requests.get(url,params=params)\n",
    "    data = response.json()\n",
    "    return data"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 87,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'status': '1', 'count': '10', 'info': 'OK', 'infocode': '10000', 'tips': [{'id': 'B000A8UIN8', 'name': '故宫博物院(暂停营业)', 'district': '北京市东城区', 'adcode': '110101', 'location': '116.397036,39.917834', 'address': '景山前街4号', 'typecode': '110201|140100', 'city': []}, {'id': 'B000A84GDN', 'name': '故宫博物院-午门', 'district': '北京市东城区', 'adcode': '110101', 'location': '116.397274,39.913849', 'address': '景山前街4号故宫博物院内', 'typecode': '110200', 'city': []}, {'id': 'B000A84AS4', 'name': '故宫博物院(南门)', 'district': '北京市东城区', 'adcode': '110101', 'location': '116.397276,39.912905', 'address': '景山前街4号故宫博物院', 'typecode': '991401', 'city': []}, {'id': 'B000A81IQA', 'name': '故宫博物院(北门)', 'district': '北京市东城区', 'adcode': '110101', 'location': '116.396909,39.923065', 'address': '景山前街4号故宫博物院', 'typecode': '991400', 'city': []}, {'id': 'B000A81GPU', 'name': '故宫博物院(东华门)', 'district': '北京市东城区', 'adcode': '110101', 'location': '116.401427,39.915136', 'address': '景山前街4号故宫博物院', 'typecode': '991400', 'city': []}, {'id': 'B000A60DA1', 'name': '天安门', 'district': '北京市东城区', 'adcode': '110101', 'location': '116.397451,39.909187', 'address': '长安街北侧', 'typecode': '110202', 'city': []}, {'id': 'B000A9JTP4', 'name': '故宫博物院(西华门)', 'district': '北京市东城区', 'adcode': '110101', 'location': '116.39272,39.914836', 'address': '景山前街4号故宫博物院内', 'typecode': '991401', 'city': []}, {'id': 'B0FFKL520U', 'name': '故宫博物院检票处', 'district': '北京市东城区', 'adcode': '110101', 'location': '116.397347,39.913913', 'address': '景山前街4号故宫博物院内', 'typecode': '070000', 'city': []}, {'id': 'B000A9PISW', 'name': '故宫博物院-神武门', 'district': '北京市东城区', 'adcode': '110101', 'location': '116.396786,39.922305', 'address': '景山前街4号北京故宫博物馆', 'typecode': '110200', 'city': []}, {'id': 'BV10000074', 'name': '故宫(公交站)', 'district': '北京市西城区', 'adcode': '110102', 'location': '116.395737,39.923275', 'address': '101路;103路;109路;124路;128路;58路;夜13路;观光1线;观光2线;观光3线', 'typecode': '150700', 'city': []}]}\n"
     ]
    }
   ],
   "source": [
    "示例_input = input_pro(keywords='故宫博物院',city='北京')\n",
    "print(示例_input)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "* 背后功能：推荐算法、人机交互"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 交通态势"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "* 希望能够确定矩形、圆形或某条道路的交通态势情况，路况信息2分钟更新一次。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 88,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 指定线路交通态势\n",
    "def traffic(name,city,level='2')->dict:\n",
    "    url = 'https://restapi.amap.com/v3/traffic/status/road?parameters'\n",
    "    params = {\n",
    "        'key': key_lin,\n",
    "        'name': name,\n",
    "        'city':city,\n",
    "        'output': 'json'\n",
    "    }\n",
    "    response = requests.get(url,params=params)\n",
    "    data = response.json()\n",
    "    return data"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 89,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'status': '1', 'info': 'OK', 'infocode': '10000', 'trafficinfo': {'description': '１０３国道：双向畅通。', 'evaluation': {'expedite': '100.00%', 'congested': '0.00%', 'blocked': '0.00%', 'unknown': '0.00%', 'status': '1', 'description': '畅通'}}}\n"
     ]
    }
   ],
   "source": [
    "测试_a = traffic(name='103国道',city='北京市')\n",
    "print(测试_a)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "* 背后功能：信息系统、人工智能"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 地理围栏"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "地理围栏服务适用于需要针对特定区域，监控用户位置与区域关系的场景中。包括但不限于：\n",
    "\n",
    "* 签到打卡类场景，在用户打卡操作前，判断用户是否已经在对应的地理围栏区域内；\n",
    "* 共享单车类场景，当用户骑车离开合法使用区域时，第一时间获知；或当用户关锁支付时，判断用户是否停在了合法区域内；\n",
    "* 线下门店促销场景，当获取到用户定位在促销门店区域的附近时，向用户发送引导进入店铺的促销信息。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 90,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 创建围栏\n",
    "def geofence(name,center)->dict:\n",
    "    url = 'https://restapi.amap.com/v4/geofence/meta?key=' + key_lin\n",
    "    params = {\n",
    "        'name':name,\n",
    "        'center': center,\n",
    "        \"radius\": \"1000\",\n",
    "        \"repeat\": \"Mon,Tues,Wed,Thur,Fri,Sat,Sun\",\n",
    "    }\n",
    "    response = requests.post(url,json=params)\n",
    "    data = response.json()\n",
    "    return data"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 91,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'data': {'message': '新增围栏已存在', 'status': '106'}, 'errcode': 0, 'errdetail': None, 'errmsg': 'OK', 'ext': None}\n"
     ]
    }
   ],
   "source": [
    "shili = geofence(name='测试围栏名称',center='113.679287,23.632575')\n",
    "print(shili)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 92,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 查询围栏\n",
    "def geofence_check(name)->dict:\n",
    "    url = 'https://restapi.amap.com/v4/geofence/meta?key=' + key_lin\n",
    "    params = {\n",
    "        'key':key_lin,\n",
    "        'name': name,\n",
    "    }\n",
    "    response = requests.get(url,params=params)\n",
    "    data = response.json()\n",
    "    return data"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 93,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'data': {'page_no': 1, 'page_size': 20, 'rs_list': [], 'total_record': 0}, 'errcode': 0, 'errdetail': None, 'errmsg': 'OK', 'ext': None}\n"
     ]
    }
   ],
   "source": [
    "查询shili围栏 = geofence_check(name='测试围栏名称')\n",
    "print(查询shili围栏)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 轨迹纠偏"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "* 用于将行车产生的轨迹坐标点匹配到道路上。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 94,
   "metadata": {},
   "outputs": [],
   "source": [
    "def driving():\n",
    "    url=\"https://restapi.amap.com/v4/grasproad/driving?key=\" + key_lin\n",
    "    body=[{\n",
    "    \"x\": 116.449429,\n",
    "    \"y\": 40.014844,\n",
    "    \"sp\": 4,\n",
    "    \"ag\": 110,\n",
    "    \"tm\": 1478831753\n",
    "    }, {\n",
    "    \"x\": 116.449639,\n",
    "    \"y\": 40.014776,\n",
    "    \"sp\": 3,\n",
    "    \"ag\": 110,\n",
    "    \"tm\": 23\n",
    "    }, {\n",
    "    \"x\": 116.449859,\n",
    "    \"y\": 40.014716,\n",
    "    \"sp\": 3,\n",
    "    \"ag\": 111,\n",
    "    \"tm\": 33\n",
    "    }, {\n",
    "    \"x\": 116.450074,\n",
    "    \"y\": 40.014658,\n",
    "    \"sp\": 3,\n",
    "    \"ag\": 110,\n",
    "    \"tm\": 31\n",
    "    }, {\n",
    "    \"x\": 116.450273,\n",
    "    \"y\": 40.014598,\n",
    "    \"sp\": 3,\n",
    "    \"ag\": 111,\n",
    "    \"tm\": 20\n",
    "    }]\n",
    "    response=requests.post(url=url,json=body).json()\n",
    "    return response"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 95,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'data': {'distance': 33.0,\n",
       "  'points': [{'x': 116.44942000249563, 'y': 40.014843356125866},\n",
       "   {'x': 116.44945705955585, 'y': 40.01453960973057}]},\n",
       " 'errcode': 0,\n",
       " 'errdetail': None,\n",
       " 'errmsg': 'OK',\n",
       " 'ext': None}"
      ]
     },
     "execution_count": 95,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "driving()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "* 背后功能：计算机视觉"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 简单应用"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "* 调用api：搜索poi，路径规划，交通态势。\n",
    "* 帮助司机更好的了解路况，以及分析最好的行车路径，搜索poi则为司机提供更便捷的服务。"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.0"
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": true,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {
    "height": "calc(100% - 180px)",
    "left": "10px",
    "top": "150px",
    "width": "307.038px"
   },
   "toc_section_display": true,
   "toc_window_display": true
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
